package com.nbicc.dp.modular.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by li on 17/12/26.
 */
@ApiIgnore()
@Slf4j
@RestController
@RequestMapping(value = "/")
public class MyExceptionHandler {

    @RequestMapping(value = "/myError" )
//    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ResponseEntity<ModelMap> myError(HttpServletRequest request, HttpServletResponse response) {
        ResponseEntity responseEntity = (ResponseEntity) request.getAttribute("result");
        response.setStatus(responseEntity.getStatusCodeValue());
        log.error(responseEntity.toString());
        return responseEntity;
    }

}
